<?php

use yii\db\Migration;

class m170906_025409_create_commission_settlement extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%commission_settlement}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'salesman_id' => $this->integer()->defaultValue(0).' COMMENT \'发卡人id\'',
                'status' => $this->smallInteger(2)->defaultValue(0).' COMMENT \'付款状态（0 未付款 1 已付款）\'',
                'settlement_amount' => $this->decimal(10,2)->defaultValue(0.00).' COMMENT \'需结算金额\'',
                'commission_money' => $this->decimal(10,2)->defaultValue(0.00).' COMMENT \'佣金\'',
                'payment_method' => $this->string(20)->defaultValue(null).' COMMENT \'付款方式\'',
                'payment_id' => $this->smallInteger(4)->defaultValue(0).' COMMENT \'付款方式\'',
                'operator' => $this->string(50)->defaultValue(null).' COMMENT \'操作人\'',
                'operator_id' => $this->integer()->defaultValue(0).' COMMENT \'操作人id\'',
                'created_at' => $this->integer()->defaultValue(0).' COMMENT \'创建时间\'',
                'created_at_settlement' => $this->integer()->defaultValue(0).' COMMENT \'付款时间\'',
                'payment_finance_id' => $this->integer()->defaultValue(0).' COMMENT \'付款人\'',
                'payment_finance_name' => $this->string(50)->defaultValue(0).' COMMENT \'付款人\'',
                'type' => $this->smallInteger()->defaultValue(0).' COMMENT \'类型 （0 发卡人 1 老师 2 班主任）\'',
            ]);
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach($dbs as $v){
            $this->db = $v;
            $this->dropTable('{{%commission_settlement}}');
        }
    }
}
